from urllib.request import Request, urlopen
import ssl

from bs4 import BeautifulSoup

if __name__ == '__main__':
    url = "https://www.tiobe.com/tiobe-index/"

    headers = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
    }

    # 针对 python 3.7 进行处理
    context = ssl.create_default_context()
    context.check_hostname = False
    context.verify_mode = ssl.CERT_NONE

    req = Request(url=url, headers=headers)
    resp = urlopen(req, context=context)
    content = resp.read()
    # print(content)

    soup = BeautifulSoup(content, "html.parser")
    # print(soup)
    print(soup.prettify())